import { ref, computed } from 'vue'
import { defineStore } from 'pinia'

export const useCounterStore = defineStore('cart', () => {
  let piniaData = ref([])
  const piniaFun = (detail, goods_id) => {
    // console.log('获取的数据', detail);
    // console.log('获取的数据详情id', goods_id);
    let pdCart = piniaData.value.find((item) => item.goods.goods_id == goods_id)
    if (pdCart) {
      pdCart.number++
    } else {
      piniaData.value.push({
        username: localStorage.getItem('username'),
        id: Math.floor(Math.random() * 100000),
        number: 1,
        checked: false,
        goods: detail,
      })

    }

  }
  return { piniaData, piniaFun }
},
  // 持久化
  {
    persist: true,
  },
)
